package com.lzx.adx.report.util;

import cn.hutool.core.io.FileUtil;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TestT {

    public static void main(String[] args) {
        List<String> strings = FileUtil.readLines(new File("E://a.txt"), StandardCharsets.UTF_8);
        List<Map<String, String>> maps = extractDateAndTransactionId(strings);
        System.out.println(maps);

    }


    private static final Pattern LOG_PATTERN = Pattern.compile(
            "^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\.\\d{3}).*流水号：(\\w+)," // 匹配流水号，直到逗号结束
    );

    /**
     * 从日志行中提取日期和流水号
     *
     * @param list 日志行字符串
     * @return 包含日期和流水号的Map
     */
    public static  List<Map<String, String>> extractDateAndTransactionId(List<String> list) {
        List<Map<String, String>> lists = new ArrayList<>();
        for (String logLine : list) {
            // 正则表达式，用于匹配日期和流水号
            String regex = "(\\d{4}-\\d{2}-\\d{2})\\s+.*?当前流水号：([a-f0-9]+)";
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(logLine);
            Map<String, String> stringStringMap = new HashMap<>();
            if (matcher.find()) {
                stringStringMap.put("date", matcher.group(1));
                stringStringMap.put("id", matcher.group(2));
            }
            lists.add(stringStringMap);
        }
        return lists;
    }
}
